<?php
/*
 * lianjie.php 用来提供操作数据库的各种函数
 * */
//连接数据库
function lianjieshujuku($servername,$name,$password){//连接数据库
    $con = mysqli_connect($servername,$name,$password);
    if(!$con )
    {
        die("数据库连接失败".mysqli_connect_error());
    }
    if(!mysqli_query($con,"set names 'utf8'"))
    {
        die("设置编码失败");
    }
    return $con;
}
//执行语句
function cunrufname($con,$mac,$ks,$kw,$ts){//保存数据到设备配置信息表

    $max=8;
    $D='d';
    $now = date('Y:m:d:H:i:s',time());
    if(!mysqli_select_db($con,'flowdate'))
    {
        //die("选择数据库失败");

    }
    if(!mysqli_query($con,"INSERT INTO `$mac` (kongshi,kongwen,time) VALUES ('$ks','$kw','$now')"))
    {
        //die("shobai".mysqli_error($con));

    }
    for($i=0;$i<$max;$i++)
    {
        $d=$D.($i+1);
        //$cun = hexdec($ts[$i]);
        mysqli_query($con,"UPDATE `$mac` SET  `$d`  = '$ts[$i]' WHERE `time` = '$now'");
    }
}

function fanhuipeizhi($con,$mac)//返回硬件配置信息
{
    if(!mysqli_select_db($con,'flower'))
    {
        die("选择数据库失败");
    }
    $req = mysqli_query($con,"select * from `fname`");
    $m = mysqli_fetch_array($req);
    echo('flower go'.'a='.$m['op'].'b='.$m['mode'].'c='.$m['kongshi'].'d='.$m['kongwen'].'e='.$m['jt'].'f='.$m['pt'].'g='.$m['at']);

}
function fanhuipeizhi2($con,$mac)//返回硬件配置信息
{
    if(!mysqli_select_db($con,'flower'))
    {
        die("选择数据库失败");
    }
    $req = mysqli_query($con,"select * from `fname`");
    $m = mysqli_fetch_array($req);
    echo('flower go'.'a=1b='.$m['mode'].'c='.$m['kongshi'].'d='.$m['kongwen'].'e='.$m['jt'].'f='.$m['pt'].'g='.$m['at']);

}




function changeop($con,$mac)//更改操作码
{
    if(!mysqli_select_db($con,'flower'))
    {
        //die("选择数据库失败");
    }
    mysqli_query($con,"update `fname` set `op` ='0' where `mac`='$mac'");
}


